.class Lcom/android/inputmethod/latin/GoogleVoiceManager;
.super Lcom/android/inputmethod/latin/VoiceKeyboardManager;
.source "GoogleVoiceManager.java"


# static fields
.field private static final TAG:Ljava/lang/String; = "###### GoogleVoiceManager ######"

.field private static mInstance:Lcom/android/inputmethod/latin/GoogleVoiceManager;


# instance fields
.field private mButton:Landroid/widget/TextView;

.field private mConnection:Landroid/content/ServiceConnection;

.field private mImageView:Landroid/widget/ImageView;

.field private mRecognitionListener:Landroid/speech/IRecognitionListener;

.field mService:Landroid/speech/IRecognitionService;

.field private mSpeechStart:I

.field private mTitleView:Landroid/widget/TextView;

.field private mUpdateVolumeRunnable:Ljava/lang/Runnable;

.field private mVolume:F

.field private mVolumeSyncObj:[Ljava/lang/Byte;

.field private mWaveBuffer:Ljava/io/ByteArrayOutputStream;

.field private mic_level_drawables:[I


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 56
    const/4 v0, 0x0

    sput-object v0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mInstance:Lcom/android/inputmethod/latin/GoogleVoiceManager;

    return-void
.end method

.method private constructor <init>(Lcom/android/inputmethod/latin/LatinIME;I)V
    .locals 1
    .parameter "context"
    .parameter "engineId"

    .prologue
    const/4 v0, 0x0

    .line 101
    invoke-direct {p0, p1, p2}, Lcom/android/inputmethod/latin/VoiceKeyboardManager;-><init>(Lcom/android/inputmethod/latin/LatinIME;I)V

    .line 59
    iput-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mButton:Landroid/widget/TextView;

    .line 61
    iput-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mWaveBuffer:Ljava/io/ByteArrayOutputStream;

    .line 62
    iput-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mService:Landroid/speech/IRecognitionService;

    .line 64
    const/4 v0, 0x7

    new-array v0, v0, [I

    fill-array-data v0, :array_0

    iput-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mic_level_drawables:[I

    .line 75
    const/4 v0, 0x0

    new-array v0, v0, [Ljava/lang/Byte;

    iput-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mVolumeSyncObj:[Ljava/lang/Byte;

    .line 76
    new-instance v0, Lcom/android/inputmethod/latin/GoogleVoiceManager$1;

    invoke-direct {v0, p0}, Lcom/android/inputmethod/latin/GoogleVoiceManager$1;-><init>(Lcom/android/inputmethod/latin/GoogleVoiceManager;)V

    iput-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mUpdateVolumeRunnable:Ljava/lang/Runnable;

    .line 336
    new-instance v0, Lcom/android/inputmethod/latin/GoogleVoiceManager$5;

    invoke-direct {v0, p0}, Lcom/android/inputmethod/latin/GoogleVoiceManager$5;-><init>(Lcom/android/inputmethod/latin/GoogleVoiceManager;)V

    iput-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mConnection:Landroid/content/ServiceConnection;

    .line 347
    new-instance v0, Lcom/android/inputmethod/latin/GoogleVoiceManager$6;

    invoke-direct {v0, p0}, Lcom/android/inputmethod/latin/GoogleVoiceManager$6;-><init>(Lcom/android/inputmethod/latin/GoogleVoiceManager;)V

    iput-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mRecognitionListener:Landroid/speech/IRecognitionListener;

    .line 102
    return-void

    .line 64
    nop

    :array_0
    .array-data 0x4
        0x34t 0x0t 0x2t 0x7ft
        0x35t 0x0t 0x2t 0x7ft
        0x36t 0x0t 0x2t 0x7ft
        0x37t 0x0t 0x2t 0x7ft
        0x38t 0x0t 0x2t 0x7ft
        0x39t 0x0t 0x2t 0x7ft
        0x3at 0x0t 0x2t 0x7ft
    .end array-data
.end method

.method static synthetic access$000(Lcom/android/inputmethod/latin/GoogleVoiceManager;)V
    .locals 0
    .parameter "x0"

    .prologue
    .line 54
    invoke-direct {p0}, Lcom/android/inputmethod/latin/GoogleVoiceManager;->updateVolumeLevel()V

    return-void
.end method

.method static synthetic access$100(Lcom/android/inputmethod/latin/GoogleVoiceManager;)Ljava/lang/Runnable;
    .locals 1
    .parameter "x0"

    .prologue
    .line 54
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mUpdateVolumeRunnable:Ljava/lang/Runnable;

    return-object v0
.end method

.method static synthetic access$1000(Lcom/android/inputmethod/latin/GoogleVoiceManager;)[Ljava/lang/Byte;
    .locals 1
    .parameter "x0"

    .prologue
    .line 54
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mVolumeSyncObj:[Ljava/lang/Byte;

    return-object v0
.end method

.method static synthetic access$1102(Lcom/android/inputmethod/latin/GoogleVoiceManager;F)F
    .locals 0
    .parameter "x0"
    .parameter "x1"

    .prologue
    .line 54
    iput p1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mVolume:F

    return p1
.end method

.method static synthetic access$200(Lcom/android/inputmethod/latin/GoogleVoiceManager;)V
    .locals 0
    .parameter "x0"

    .prologue
    .line 54
    invoke-direct {p0}, Lcom/android/inputmethod/latin/GoogleVoiceManager;->showSpeakNow()V

    return-void
.end method

.method static synthetic access$300(Lcom/android/inputmethod/latin/GoogleVoiceManager;)Landroid/widget/ImageView;
    .locals 1
    .parameter "x0"

    .prologue
    .line 54
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mImageView:Landroid/widget/ImageView;

    return-object v0
.end method

.method static synthetic access$400(Lcom/android/inputmethod/latin/GoogleVoiceManager;)Landroid/widget/TextView;
    .locals 1
    .parameter "x0"

    .prologue
    .line 54
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mTitleView:Landroid/widget/TextView;

    return-object v0
.end method

.method static synthetic access$500(Lcom/android/inputmethod/latin/GoogleVoiceManager;)Landroid/widget/TextView;
    .locals 1
    .parameter "x0"

    .prologue
    .line 54
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mButton:Landroid/widget/TextView;

    return-object v0
.end method

.method static synthetic access$600(Lcom/android/inputmethod/latin/GoogleVoiceManager;)V
    .locals 0
    .parameter "x0"

    .prologue
    .line 54
    invoke-direct {p0}, Lcom/android/inputmethod/latin/GoogleVoiceManager;->showListening()V

    return-void
.end method

.method static synthetic access$700(Lcom/android/inputmethod/latin/GoogleVoiceManager;)I
    .locals 1
    .parameter "x0"

    .prologue
    .line 54
    iget v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mSpeechStart:I

    return v0
.end method

.method static synthetic access$702(Lcom/android/inputmethod/latin/GoogleVoiceManager;I)I
    .locals 0
    .parameter "x0"
    .parameter "x1"

    .prologue
    .line 54
    iput p1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mSpeechStart:I

    return p1
.end method

.method static synthetic access$800(Lcom/android/inputmethod/latin/GoogleVoiceManager;)Ljava/io/ByteArrayOutputStream;
    .locals 1
    .parameter "x0"

    .prologue
    .line 54
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mWaveBuffer:Ljava/io/ByteArrayOutputStream;

    return-object v0
.end method

.method static synthetic access$900(Lcom/android/inputmethod/latin/GoogleVoiceManager;Ljava/io/ByteArrayOutputStream;II)V
    .locals 0
    .parameter "x0"
    .parameter "x1"
    .parameter "x2"
    .parameter "x3"

    .prologue
    .line 54
    invoke-direct {p0, p1, p2, p3}, Lcom/android/inputmethod/latin/GoogleVoiceManager;->showWorking(Ljava/io/ByteArrayOutputStream;II)V

    return-void
.end method

.method private drawWave(Ljava/nio/ShortBuffer;Landroid/graphics/Canvas;II)V
    .locals 22
    .parameter "waveBuf"
    .parameter "canvas"
    .parameter "w"
    .parameter "h"

    .prologue
    .line 266
    const/16 v11, 0xc8

    .line 267
    .local v11, numSamplePerWave:I
    const/high16 v6, 0x3f80

    .line 268
    .local v6, MIN_STROKE_WIDTH:F
    const/high16 v5, 0x4040

    .line 269
    .local v5, MAX_STROKE_WIDTH:F
    const/high16 v4, 0x4040

    .line 271
    .local v4, CORNER_RADIUS:F
    invoke-virtual/range {p1 .. p1}, Ljava/nio/ShortBuffer;->limit()I

    move-result v20

    move/from16 v0, v20

    div-int/lit16 v0, v0, 0xc8

    move v10, v0

    .line 272
    .local v10, numSample:I
    move v0, v10

    move/from16 v1, p3

    if-le v0, v1, :cond_0

    move/from16 v10, p3

    .line 273
    :cond_0
    div-int/lit8 v19, p4, 0x2

    .line 274
    .local v19, yMax:I
    const/high16 v20, 0x4600

    move/from16 v0, v19

    int-to-float v0, v0

    move/from16 v21, v0

    div-float v14, v20, v21

    .line 275
    .local v14, scaleY:F
    move/from16 v0, p3

    int-to-float v0, v0

    move/from16 v20, v0

    move v0, v10

    int-to-float v0, v0

    move/from16 v21, v0

    div-float v8, v20, v21

    .line 276
    .local v8, deltaX:F
    const/4 v15, 0x1

    .line 282
    .local v15, sign:I
    new-instance v12, Landroid/graphics/Paint;

    invoke-direct {v12}, Landroid/graphics/Paint;-><init>()V

    .line 283
    .local v12, paint:Landroid/graphics/Paint;
    const/16 v20, -0x1

    move-object v0, v12

    move/from16 v1, v20

    invoke-virtual {v0, v1}, Landroid/graphics/Paint;->setColor(I)V

    .line 286
    const/high16 v20, 0x4040

    cmpl-float v20, v8, v20

    if-lez v20, :cond_1

    .line 287
    const/high16 v16, 0x4040

    .line 291
    .local v16, strokeWidth:F
    :goto_0
    move-object v0, v12

    move/from16 v1, v16

    invoke-virtual {v0, v1}, Landroid/graphics/Paint;->setStrokeWidth(F)V

    .line 292
    sget-object v20, Landroid/graphics/Paint$Style;->STROKE:Landroid/graphics/Paint$Style;

    move-object v0, v12

    move-object/from16 v1, v20

    invoke-virtual {v0, v1}, Landroid/graphics/Paint;->setStyle(Landroid/graphics/Paint$Style;)V

    .line 293
    const/16 v20, 0x1

    move-object v0, v12

    move/from16 v1, v20

    invoke-virtual {v0, v1}, Landroid/graphics/Paint;->setAntiAlias(Z)V

    .line 294
    new-instance v20, Landroid/graphics/CornerPathEffect;

    const/high16 v21, 0x4040

    invoke-direct/range {v20 .. v21}, Landroid/graphics/CornerPathEffect;-><init>(F)V

    move-object v0, v12

    move-object/from16 v1, v20

    invoke-virtual {v0, v1}, Landroid/graphics/Paint;->setPathEffect(Landroid/graphics/PathEffect;)Landroid/graphics/PathEffect;

    .line 295
    const/16 v20, 0x0

    move/from16 v0, v19

    int-to-float v0, v0

    move/from16 v21, v0

    move-object/from16 v0, p2

    move/from16 v1, v20

    move/from16 v2, v21

    invoke-virtual {v0, v1, v2}, Landroid/graphics/Canvas;->translate(FF)V

    .line 296
    const/16 v17, 0x0

    .local v17, x:F
    const/16 v18, 0x0

    .line 297
    .local v18, y:F
    new-instance v13, Landroid/graphics/Path;

    invoke-direct {v13}, Landroid/graphics/Path;-><init>()V

    .line 298
    .local v13, path:Landroid/graphics/Path;
    move-object v0, v13

    move/from16 v1, v17

    move/from16 v2, v18

    invoke-virtual {v0, v1, v2}, Landroid/graphics/Path;->moveTo(FF)V

    .line 300
    const/4 v9, 0x0

    .local v9, i:I
    :goto_1
    if-ge v9, v10, :cond_2

    .line 301
    const/16 v20, 0xc8

    move-object/from16 v0, p0

    move-object/from16 v1, p1

    move v2, v9

    move/from16 v3, v20

    invoke-direct {v0, v1, v2, v3}, Lcom/android/inputmethod/latin/GoogleVoiceManager;->getAverageAbs(Ljava/nio/ShortBuffer;II)I

    move-result v7

    .line 302
    .local v7, avabs:I
    move v0, v7

    int-to-float v0, v0

    move/from16 v20, v0

    div-float v20, v20, v14

    const/16 v21, 0x2

    sub-int v21, v19, v21

    move/from16 v0, v21

    int-to-float v0, v0

    move/from16 v21, v0

    invoke-static/range {v20 .. v21}, Ljava/lang/Math;->min(FF)F

    move-result v20

    move v0, v15

    int-to-float v0, v0

    move/from16 v21, v0

    mul-float v18, v20, v21

    .line 303
    move-object v0, v13

    move/from16 v1, v17

    move/from16 v2, v18

    invoke-virtual {v0, v1, v2}, Landroid/graphics/Path;->lineTo(FF)V

    .line 304
    add-float v17, v17, v8

    .line 305
    move-object v0, v13

    move/from16 v1, v17

    move/from16 v2, v18

    invoke-virtual {v0, v1, v2}, Landroid/graphics/Path;->lineTo(FF)V

    .line 306
    neg-int v15, v15

    .line 300
    add-int/lit8 v9, v9, 0x1

    goto :goto_1

    .line 289
    .end local v7           #avabs:I
    .end local v9           #i:I
    .end local v13           #path:Landroid/graphics/Path;
    .end local v16           #strokeWidth:F
    .end local v17           #x:F
    .end local v18           #y:F
    :cond_1
    const/high16 v20, 0x3f80

    const v21, 0x3d4ccccd

    sub-float v21, v8, v21

    invoke-static/range {v20 .. v21}, Ljava/lang/Math;->max(FF)F

    move-result v16

    .restart local v16       #strokeWidth:F
    goto/16 :goto_0

    .line 308
    .restart local v9       #i:I
    .restart local v13       #path:Landroid/graphics/Path;
    .restart local v17       #x:F
    .restart local v18       #y:F
    :cond_2
    move-object/from16 v0, p2

    move-object v1, v13

    move-object v2, v12

    invoke-virtual {v0, v1, v2}, Landroid/graphics/Canvas;->drawPath(Landroid/graphics/Path;Landroid/graphics/Paint;)V

    .line 309
    return-void
.end method

.method private getAverageAbs(Ljava/nio/ShortBuffer;II)I
    .locals 4
    .parameter "waveBuf"
    .parameter "index"
    .parameter "npw"

    .prologue
    .line 312
    mul-int v1, p2, p3

    .line 313
    .local v1, start:I
    const/4 v2, 0x0

    .line 314
    .local v2, total:I
    const/4 v0, 0x0

    .local v0, i:I
    :goto_0
    if-ge v0, p3, :cond_0

    .line 315
    add-int v3, v0, v1

    invoke-virtual {p1, v3}, Ljava/nio/ShortBuffer;->get(I)S

    move-result v3

    invoke-static {v3}, Ljava/lang/Math;->abs(I)I

    move-result v3

    add-int/2addr v2, v3

    .line 314
    add-int/lit8 v0, v0, 0x1

    goto :goto_0

    .line 317
    :cond_0
    div-int v3, v2, p3

    return v3
.end method

.method public static getInstance(Lcom/android/inputmethod/latin/LatinIME;)Lcom/android/inputmethod/latin/GoogleVoiceManager;
    .locals 2
    .parameter "context"

    .prologue
    .line 87
    sget-object v0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mInstance:Lcom/android/inputmethod/latin/GoogleVoiceManager;

    if-nez v0, :cond_0

    .line 88
    new-instance v0, Lcom/android/inputmethod/latin/GoogleVoiceManager;

    const/4 v1, 0x1

    invoke-direct {v0, p0, v1}, Lcom/android/inputmethod/latin/GoogleVoiceManager;-><init>(Lcom/android/inputmethod/latin/LatinIME;I)V

    sput-object v0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mInstance:Lcom/android/inputmethod/latin/GoogleVoiceManager;

    .line 97
    :goto_0
    sget-object v0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mInstance:Lcom/android/inputmethod/latin/GoogleVoiceManager;

    return-object v0

    .line 90
    :cond_0
    sget-object v0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mInstance:Lcom/android/inputmethod/latin/GoogleVoiceManager;

    iget-object v0, v0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mContext:Lcom/android/inputmethod/latin/LatinIME;

    if-nez v0, :cond_1

    sget-object v0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mInstance:Lcom/android/inputmethod/latin/GoogleVoiceManager;

    iget-object v0, v0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mService:Landroid/speech/IRecognitionService;

    if-eqz v0, :cond_2

    .line 91
    :cond_1
    const-string v0, "###### GoogleVoiceManager ######"

    const-string v1, "Global instance is reused by onFinish() was not called in last usage!!"

    invoke-static {v0, v1}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    .line 92
    sget-object v0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mInstance:Lcom/android/inputmethod/latin/GoogleVoiceManager;

    invoke-virtual {v0}, Lcom/android/inputmethod/latin/GoogleVoiceManager;->onFinish()V

    .line 94
    :cond_2
    sget-object v0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mInstance:Lcom/android/inputmethod/latin/GoogleVoiceManager;

    iput-object p0, v0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mContext:Lcom/android/inputmethod/latin/LatinIME;

    goto :goto_0
.end method

.method private showListening()V
    .locals 4

    .prologue
    .line 204
    iget-boolean v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mIsVoiceKeyboardShown:Z

    if-eqz v0, :cond_0

    .line 205
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mHandler:Landroid/os/Handler;

    new-instance v1, Lcom/android/inputmethod/latin/GoogleVoiceManager$3;

    invoke-direct {v1, p0}, Lcom/android/inputmethod/latin/GoogleVoiceManager$3;-><init>(Lcom/android/inputmethod/latin/GoogleVoiceManager;)V

    invoke-virtual {v0, v1}, Landroid/os/Handler;->post(Ljava/lang/Runnable;)Z

    .line 211
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mUpdateVolumeRunnable:Ljava/lang/Runnable;

    const-wide/16 v2, 0x32

    invoke-virtual {v0, v1, v2, v3}, Landroid/os/Handler;->postDelayed(Ljava/lang/Runnable;J)Z

    .line 213
    :cond_0
    return-void
.end method

.method private showSpeakNow()V
    .locals 4

    .prologue
    .line 216
    iget-boolean v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mIsVoiceKeyboardShown:Z

    if-eqz v0, :cond_0

    .line 217
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mImageView:Landroid/widget/ImageView;

    iget-object v1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mContext:Lcom/android/inputmethod/latin/LatinIME;

    invoke-virtual {v1}, Lcom/android/inputmethod/latin/LatinIME;->getResources()Landroid/content/res/Resources;

    move-result-object v1

    iget-object v2, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mic_level_drawables:[I

    const/4 v3, 0x0

    aget v2, v2, v3

    invoke-virtual {v1, v2}, Landroid/content/res/Resources;->getDrawable(I)Landroid/graphics/drawable/Drawable;

    move-result-object v1

    invoke-virtual {v0, v1}, Landroid/widget/ImageView;->setImageDrawable(Landroid/graphics/drawable/Drawable;)V

    .line 218
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mTitleView:Landroid/widget/TextView;

    const-string v1, "Speak now"

    invoke-virtual {v0, v1}, Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V

    .line 220
    :cond_0
    return-void
.end method

.method private showStartState()V
    .locals 3

    .prologue
    .line 199
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mImageView:Landroid/widget/ImageView;

    iget-object v1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mContext:Lcom/android/inputmethod/latin/LatinIME;

    invoke-virtual {v1}, Lcom/android/inputmethod/latin/LatinIME;->getResources()Landroid/content/res/Resources;

    move-result-object v1

    const v2, 0x7f020032

    invoke-virtual {v1, v2}, Landroid/content/res/Resources;->getDrawable(I)Landroid/graphics/drawable/Drawable;

    move-result-object v1

    invoke-virtual {v0, v1}, Landroid/widget/ImageView;->setImageDrawable(Landroid/graphics/drawable/Drawable;)V

    .line 200
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mTitleView:Landroid/widget/TextView;

    const v1, 0x7f0a0051

    invoke-virtual {v0, v1}, Landroid/widget/TextView;->setText(I)V

    .line 201
    return-void
.end method

.method private showWorking(Ljava/io/ByteArrayOutputStream;II)V
    .locals 8
    .parameter "waveBuf"
    .parameter "start"
    .parameter "end"

    .prologue
    const/16 v7, 0xbb8

    .line 241
    iget-boolean v6, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mIsVoiceKeyboardShown:Z

    if-eqz v6, :cond_0

    .line 243
    iget-object v6, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mVoiceKeyboardView:Landroid/view/View;

    invoke-virtual {v6}, Landroid/view/View;->getWidth()I

    move-result v4

    .line 244
    .local v4, w:I
    iget-object v6, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mImageView:Landroid/widget/ImageView;

    invoke-virtual {v6}, Landroid/widget/ImageView;->getHeight()I

    move-result v3

    .line 249
    .local v3, h:I
    sget-object v6, Landroid/graphics/Bitmap$Config;->ARGB_8888:Landroid/graphics/Bitmap$Config;

    invoke-static {v4, v3, v6}, Landroid/graphics/Bitmap;->createBitmap(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;

    move-result-object v5

    .line 250
    .local v5, wave_bmp:Landroid/graphics/Bitmap;
    new-instance v2, Landroid/graphics/Canvas;

    invoke-direct {v2, v5}, Landroid/graphics/Canvas;-><init>(Landroid/graphics/Bitmap;)V

    .line 251
    .local v2, canvas:Landroid/graphics/Canvas;
    const/16 v0, 0xbb8

    .line 252
    .local v0, WAVE_BUFFER_ADJUST:I
    move v1, p2

    .line 253
    .local v1, adjust_start:I
    if-lt p2, v7, :cond_1

    .line 254
    sub-int v1, p2, v7

    .line 258
    :goto_0
    invoke-virtual {p1}, Ljava/io/ByteArrayOutputStream;->toByteArray()[B

    move-result-object v6

    sub-int v7, p3, v1

    invoke-static {v6, v1, v7}, Ljava/nio/ByteBuffer;->wrap([BII)Ljava/nio/ByteBuffer;

    move-result-object v6

    invoke-static {}, Ljava/nio/ByteOrder;->nativeOrder()Ljava/nio/ByteOrder;

    move-result-object v7

    invoke-virtual {v6, v7}, Ljava/nio/ByteBuffer;->order(Ljava/nio/ByteOrder;)Ljava/nio/ByteBuffer;

    move-result-object v6

    invoke-virtual {v6}, Ljava/nio/ByteBuffer;->asShortBuffer()Ljava/nio/ShortBuffer;

    move-result-object v6

    invoke-direct {p0, v6, v2, v4, v3}, Lcom/android/inputmethod/latin/GoogleVoiceManager;->drawWave(Ljava/nio/ShortBuffer;Landroid/graphics/Canvas;II)V

    .line 260
    iget-object v6, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mImageView:Landroid/widget/ImageView;

    invoke-virtual {v6, v5}, Landroid/widget/ImageView;->setImageBitmap(Landroid/graphics/Bitmap;)V

    .line 261
    iget-object v6, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mTitleView:Landroid/widget/TextView;

    const-string v7, "Working"

    invoke-virtual {v6, v7}, Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V

    .line 263
    .end local v0           #WAVE_BUFFER_ADJUST:I
    .end local v1           #adjust_start:I
    .end local v2           #canvas:Landroid/graphics/Canvas;
    .end local v3           #h:I
    .end local v4           #w:I
    .end local v5           #wave_bmp:Landroid/graphics/Bitmap;
    :cond_0
    return-void

    .line 256
    .restart local v0       #WAVE_BUFFER_ADJUST:I
    .restart local v1       #adjust_start:I
    .restart local v2       #canvas:Landroid/graphics/Canvas;
    .restart local v3       #h:I
    .restart local v4       #w:I
    .restart local v5       #wave_bmp:Landroid/graphics/Bitmap;
    :cond_1
    const/4 v1, 0x0

    goto :goto_0
.end method

.method private updateVolumeLevel()V
    .locals 8

    .prologue
    .line 223
    const/high16 v1, 0x4170

    .line 224
    .local v1, MIN_MICPHONE_LEVEL:F
    const/high16 v0, 0x41f0

    .line 228
    .local v0, MAX_MICPHONE_LEVEL:F
    iget-object v5, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mVolumeSyncObj:[Ljava/lang/Byte;

    monitor-enter v5

    .line 229
    :try_start_0
    iget v4, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mVolume:F

    .line 230
    .local v4, volume:F
    monitor-exit v5
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 231
    iget-object v5, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mic_level_drawables:[I

    array-length v5, v5

    const/4 v6, 0x1

    sub-int v3, v5, v6

    .line 232
    .local v3, maxLevel:I
    cmpg-float v5, v4, v1

    if-gez v5, :cond_0

    const/4 v2, 0x0

    .line 237
    .local v2, level:I
    :goto_0
    iget-object v5, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mImageView:Landroid/widget/ImageView;

    iget-object v6, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mContext:Lcom/android/inputmethod/latin/LatinIME;

    invoke-virtual {v6}, Lcom/android/inputmethod/latin/LatinIME;->getResources()Landroid/content/res/Resources;

    move-result-object v6

    iget-object v7, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mic_level_drawables:[I

    aget v7, v7, v2

    invoke-virtual {v6, v7}, Landroid/content/res/Resources;->getDrawable(I)Landroid/graphics/drawable/Drawable;

    move-result-object v6

    invoke-virtual {v5, v6}, Landroid/widget/ImageView;->setImageDrawable(Landroid/graphics/drawable/Drawable;)V

    .line 238
    return-void

    .line 230
    .end local v2           #level:I
    .end local v3           #maxLevel:I
    .end local v4           #volume:F
    :catchall_0
    move-exception v6

    :try_start_1
    monitor-exit v5
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    throw v6

    .line 233
    .restart local v3       #maxLevel:I
    .restart local v4       #volume:F
    :cond_0
    cmpl-float v5, v4, v0

    if-lez v5, :cond_1

    move v2, v3

    .restart local v2       #level:I
    goto :goto_0

    .line 235
    .end local v2           #level:I
    :cond_1
    sub-float v5, v4, v1

    sub-float v6, v0, v1

    div-float/2addr v5, v6

    int-to-float v6, v3

    mul-float/2addr v5, v6

    invoke-static {v5}, Ljava/lang/Math;->round(F)I

    move-result v2

    .restart local v2       #level:I
    goto :goto_0
.end method


# virtual methods
.method public createVoiceKeyboardView()Landroid/view/View;
    .locals 8

    .prologue
    .line 106
    iget-object v5, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mContext:Lcom/android/inputmethod/latin/LatinIME;

    const v6, 0x7f030003

    const/4 v7, 0x0

    invoke-static {v5, v6, v7}, Landroid/view/View;->inflate(Landroid/content/Context;ILandroid/view/ViewGroup;)Landroid/view/View;

    move-result-object v4

    .line 107
    .local v4, voiceKeyBoardView:Landroid/view/View;
    const v5, 0x7f0b0008

    invoke-virtual {v4, v5}, Landroid/view/View;->findViewById(I)Landroid/view/View;

    move-result-object v5

    check-cast v5, Landroid/widget/TextView;

    iput-object v5, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mButton:Landroid/widget/TextView;

    .line 108
    iget-object v5, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mButton:Landroid/widget/TextView;

    new-instance v6, Lcom/android/inputmethod/latin/GoogleVoiceManager$2;

    invoke-direct {v6, p0}, Lcom/android/inputmethod/latin/GoogleVoiceManager$2;-><init>(Lcom/android/inputmethod/latin/GoogleVoiceManager;)V

    invoke-virtual {v5, v6}, Landroid/widget/TextView;->setOnClickListener(Landroid/view/View$OnClickListener;)V

    .line 113
    const v5, 0x7f0b0007

    invoke-virtual {v4, v5}, Landroid/view/View;->findViewById(I)Landroid/view/View;

    move-result-object v5

    check-cast v5, Landroid/widget/ImageView;

    iput-object v5, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mImageView:Landroid/widget/ImageView;

    .line 114
    const v5, 0x7f0b0006

    invoke-virtual {v4, v5}, Landroid/view/View;->findViewById(I)Landroid/view/View;

    move-result-object v5

    check-cast v5, Landroid/widget/TextView;

    iput-object v5, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mTitleView:Landroid/widget/TextView;

    .line 116
    iget-object v5, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mContext:Lcom/android/inputmethod/latin/LatinIME;

    invoke-virtual {v5}, Lcom/android/inputmethod/latin/LatinIME;->getWindow()Landroid/app/Dialog;

    move-result-object v5

    const v6, 0x102001e

    invoke-virtual {v5, v6}, Landroid/app/Dialog;->findViewById(I)Landroid/view/View;

    move-result-object v5

    check-cast v5, Landroid/widget/FrameLayout;

    const/4 v6, 0x0

    invoke-virtual {v5, v6}, Landroid/widget/FrameLayout;->getChildAt(I)Landroid/view/View;

    move-result-object v2

    .line 117
    .local v2, keyboardView:Landroid/view/View;
    if-eqz v2, :cond_0

    .line 118
    const v5, 0x7f0b0005

    invoke-virtual {v4, v5}, Landroid/view/View;->findViewById(I)Landroid/view/View;

    move-result-object v3

    check-cast v3, Landroid/widget/LinearLayout;

    .line 119
    .local v3, statusContainer:Landroid/widget/LinearLayout;
    iget-object v5, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mContext:Lcom/android/inputmethod/latin/LatinIME;

    invoke-virtual {v5}, Lcom/android/inputmethod/latin/LatinIME;->getResources()Landroid/content/res/Resources;

    move-result-object v5

    const v6, 0x7f090004

    invoke-virtual {v5, v6}, Landroid/content/res/Resources;->getDimensionPixelSize(I)I

    move-result v0

    .line 120
    .local v0, buttonHeight:I
    invoke-virtual {v2}, Landroid/view/View;->getHeight()I

    move-result v5

    sub-int v1, v5, v0

    .line 121
    .local v1, height:I
    new-instance v5, Landroid/widget/LinearLayout$LayoutParams;

    const/4 v6, -0x1

    invoke-direct {v5, v6, v1}, Landroid/widget/LinearLayout$LayoutParams;-><init>(II)V

    invoke-virtual {v3, v5}, Landroid/widget/LinearLayout;->setLayoutParams(Landroid/view/ViewGroup$LayoutParams;)V

    .line 124
    .end local v0           #buttonHeight:I
    .end local v1           #height:I
    .end local v3           #statusContainer:Landroid/widget/LinearLayout;
    :cond_0
    return-object v4
.end method

.method public onCancel()V
    .locals 2

    .prologue
    .line 160
    invoke-super {p0}, Lcom/android/inputmethod/latin/VoiceKeyboardManager;->onCancel()V

    .line 161
    iget-boolean v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mIsErrorMessageShown:Z

    if-eqz v0, :cond_1

    .line 162
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mHideErrorMessageRunnable:Ljava/lang/Runnable;

    invoke-virtual {v0, v1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

    .line 163
    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mIsErrorMessageShown:Z

    .line 170
    :cond_0
    :goto_0
    return-void

    .line 165
    :cond_1
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mUpdateVolumeRunnable:Ljava/lang/Runnable;

    invoke-virtual {v0, v1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

    .line 166
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mService:Landroid/speech/IRecognitionService;

    if-eqz v0, :cond_0

    .line 167
    :try_start_0
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mService:Landroid/speech/IRecognitionService;

    invoke-interface {v0}, Landroid/speech/IRecognitionService;->cancel()V
    :try_end_0
    .catch Landroid/os/RemoteException; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    :catch_0
    move-exception v0

    goto :goto_0
.end method

.method public onError(I)V
    .locals 2
    .parameter "error"

    .prologue
    .line 194
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mUpdateVolumeRunnable:Ljava/lang/Runnable;

    invoke-virtual {v0, v1}, Landroid/os/Handler;->removeCallbacks(Ljava/lang/Runnable;)V

    .line 195
    invoke-super {p0, p1}, Lcom/android/inputmethod/latin/VoiceKeyboardManager;->onError(I)V

    .line 196
    return-void
.end method

.method public onFinish()V
    .locals 4

    .prologue
    const/4 v3, 0x0

    .line 174
    iget-object v1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mService:Landroid/speech/IRecognitionService;

    if-eqz v1, :cond_0

    .line 175
    :try_start_0
    iget-object v1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mService:Landroid/speech/IRecognitionService;

    invoke-interface {v1}, Landroid/speech/IRecognitionService;->cancel()V
    :try_end_0
    .catch Landroid/os/RemoteException; {:try_start_0 .. :try_end_0} :catch_1

    .line 176
    :goto_0
    iget-object v1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mContext:Lcom/android/inputmethod/latin/LatinIME;

    iget-object v2, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mConnection:Landroid/content/ServiceConnection;

    invoke-virtual {v1, v2}, Lcom/android/inputmethod/latin/LatinIME;->unbindService(Landroid/content/ServiceConnection;)V

    .line 177
    iput-object v3, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mService:Landroid/speech/IRecognitionService;

    .line 179
    :cond_0
    iput-object v3, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mButton:Landroid/widget/TextView;

    .line 180
    iput-object v3, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mImageView:Landroid/widget/ImageView;

    .line 181
    iput-object v3, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mTitleView:Landroid/widget/TextView;

    .line 184
    :try_start_1
    iget-object v1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mWaveBuffer:Ljava/io/ByteArrayOutputStream;

    invoke-virtual {v1}, Ljava/io/ByteArrayOutputStream;->close()V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    .line 188
    :goto_1
    iput-object v3, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mWaveBuffer:Ljava/io/ByteArrayOutputStream;

    .line 189
    invoke-super {p0}, Lcom/android/inputmethod/latin/VoiceKeyboardManager;->onFinish()V

    .line 190
    return-void

    .line 185
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 186
    .local v0, ex:Ljava/lang/Exception;
    const-string v1, "###### GoogleVoiceManager ######"

    const-string v2, "Error closing the wave buffer!!!"

    invoke-static {v1, v2}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_1

    .line 175
    .end local v0           #ex:Ljava/lang/Exception;
    :catch_1
    move-exception v1

    goto :goto_0
.end method

.method public showErrorMessage(Ljava/lang/String;)V
    .locals 4
    .parameter "msg"

    .prologue
    .line 322
    iget-boolean v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mIsVoiceKeyboardShown:Z

    if-eqz v0, :cond_0

    .line 323
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mHandler:Landroid/os/Handler;

    new-instance v1, Lcom/android/inputmethod/latin/GoogleVoiceManager$4;

    invoke-direct {v1, p0, p1}, Lcom/android/inputmethod/latin/GoogleVoiceManager$4;-><init>(Lcom/android/inputmethod/latin/GoogleVoiceManager;Ljava/lang/String;)V

    invoke-virtual {v0, v1}, Landroid/os/Handler;->post(Ljava/lang/Runnable;)Z

    .line 332
    iget-object v0, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mHandler:Landroid/os/Handler;

    iget-object v1, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mHideErrorMessageRunnable:Ljava/lang/Runnable;

    const-wide/16 v2, 0x7d0

    invoke-virtual {v0, v1, v2, v3}, Landroid/os/Handler;->postDelayed(Ljava/lang/Runnable;J)Z

    .line 334
    :cond_0
    return-void
.end method

.method public startRecognition()V
    .locals 6

    .prologue
    .line 129
    iget-object v2, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mService:Landroid/speech/IRecognitionService;

    if-nez v2, :cond_1

    .line 131
    iget-object v2, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mContext:Lcom/android/inputmethod/latin/LatinIME;

    sget-object v3, Landroid/speech/RecognitionServiceUtil;->sDefaultIntent:Landroid/content/Intent;

    iget-object v4, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mConnection:Landroid/content/ServiceConnection;

    const/4 v5, 0x1

    invoke-virtual {v2, v3, v4, v5}, Lcom/android/inputmethod/latin/LatinIME;->bindService(Landroid/content/Intent;Landroid/content/ServiceConnection;I)Z

    move-result v2

    if-nez v2, :cond_0

    .line 136
    invoke-virtual {p0}, Lcom/android/inputmethod/latin/GoogleVoiceManager;->showVoiceKeyboard()V

    .line 137
    const-string v2, "Google voice unavailable!!"

    invoke-virtual {p0, v2}, Lcom/android/inputmethod/latin/GoogleVoiceManager;->showErrorMessage(Ljava/lang/String;)V

    .line 156
    :cond_0
    :goto_0
    return-void

    .line 140
    :cond_1
    invoke-virtual {p0}, Lcom/android/inputmethod/latin/GoogleVoiceManager;->showVoiceKeyboard()V

    .line 141
    iget-object v2, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mWaveBuffer:Ljava/io/ByteArrayOutputStream;

    if-nez v2, :cond_3

    .line 142
    new-instance v2, Ljava/io/ByteArrayOutputStream;

    invoke-direct {v2}, Ljava/io/ByteArrayOutputStream;-><init>()V

    iput-object v2, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mWaveBuffer:Ljava/io/ByteArrayOutputStream;

    .line 146
    :cond_2
    :goto_1
    invoke-direct {p0}, Lcom/android/inputmethod/latin/GoogleVoiceManager;->showStartState()V

    .line 147
    new-instance v1, Landroid/content/Intent;

    const-string v2, "android.speech.action.RECOGNIZE_SPEECH"

    invoke-direct {v1, v2}, Landroid/content/Intent;-><init>(Ljava/lang/String;)V

    .line 148
    .local v1, i:Landroid/content/Intent;
    const-string v2, "android.speech.extra.LANGUAGE_MODEL"

    const-string v3, "free_form"

    invoke-virtual {v1, v2, v3}, Landroid/content/Intent;->putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;

    .line 149
    const-string v2, "calling_package"

    const-string v3, "LatinIME"

    invoke-virtual {v1, v2, v3}, Landroid/content/Intent;->putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;

    .line 151
    :try_start_0
    iget-object v2, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mService:Landroid/speech/IRecognitionService;

    iget-object v3, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mRecognitionListener:Landroid/speech/IRecognitionListener;

    invoke-interface {v2, v1, v3}, Landroid/speech/IRecognitionService;->startListening(Landroid/content/Intent;Landroid/speech/IRecognitionListener;)V
    :try_end_0
    .catch Landroid/os/RemoteException; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 152
    :catch_0
    move-exception v2

    move-object v0, v2

    .line 153
    .local v0, e:Landroid/os/RemoteException;
    const-string v2, "###### GoogleVoiceManager ######"

    const-string v3, "start listening error!"

    invoke-static {v2, v3}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_0

    .line 143
    .end local v0           #e:Landroid/os/RemoteException;
    .end local v1           #i:Landroid/content/Intent;
    :cond_3
    iget-object v2, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mWaveBuffer:Ljava/io/ByteArrayOutputStream;

    invoke-virtual {v2}, Ljava/io/ByteArrayOutputStream;->size()I

    move-result v2

    if-lez v2, :cond_2

    .line 144
    iget-object v2, p0, Lcom/android/inputmethod/latin/GoogleVoiceManager;->mWaveBuffer:Ljava/io/ByteArrayOutputStream;

    invoke-virtual {v2}, Ljava/io/ByteArrayOutputStream;->reset()V

    goto :goto_1
.end method
